import * as types from '../mutation-types'

const defaultData = {
  address: "", //收货地址
  cardNum: "", //身份证号
  // customerContactId: '', //收货人id
  // delivery: "0", //交货方式
  door: "", //上门地址
  // isDoor: 0, //是否上门
  // notice: 0, //是否通知收货1是
  orderId: "",
  orderProducts: [
    {
      name: "", //商品名
      num: '', //数量
      packages: "", //包装
      volume: "", //体积
      weight: "" //重量
    }
  ],
  payStatus: "", //付款状态
  receivables: "", //请选择收款类型
  refundAsk: "", //回单要求
  refundRemark: "", //回单备注
  remark: "" //备注
}
const state = {
  isShow: false,
  orderData: {
    address: "", //收货地址
    cardNum: "", //身份证号
    customerContactId: '', //收货人id
    delivery: "", //交货方式
    door: "", //上门地址
    isDoor: 0, //是否上门
    notice: 0, //是否通知收货1是
    orderId: "",
    orderProducts: [
      {
        name: "", //商品名
        num: '', //数量
        packages: "", //包装
        volume: "", //体积
        weight: "" //重量
      }
    ],
    payStatus: "", //付款状态
    receivables: "", //请选择收款类型
    refundAsk: "", //回单要求
    refundRemark: "", //回单备注
    remark: "" //备注
  },
  defaultUser: {id:'',name:''}
}
const getters = {
  isShow: state => state.isShow,
  orderData: state => state.orderData,
  defaultUser: state => state.defaultUser,
}

const actions = {
  setModal({ commit, state }, payload) {
    commit(types.SET_MOADL, payload);
  },
  setOrderData({ commit, state }, payload) {
    commit(types.SET_ORDER_DATA, payload);
  },
  setUserInfo({ commit, state }, payload) {
    commit(types.USER_INFO, payload);
  }
}

const mutations = {
  [types.SET_MOADL](state, payload) {
    state.isShow = payload
  },
  [types.SET_ORDER_DATA](state, payload) {
    if (payload.type&&payload.type=='reset') {
        state.orderData= { ...state.orderData, ...defaultData }
    } else {
      state.orderData = { ...state.orderData, ...payload.data }
    }
  },
  [types.USER_INFO](state, payload) {
    state.defaultUser = payload
  },
}
export default { state, getters, actions, mutations }
